﻿using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using SpecFlowDemo.Api;
using System.Threading.Tasks;
using TechTalk.SpecFlow;

namespace SpecFlowDemo.Specs.Support.Hooks
{
    [Binding]
    public sealed class WebHostHook
    {
        private static IHost _host;

        [BeforeTestRun]
        public static async Task BeforeTestRun()
        {
            _host = Program.CreateHostBuilder(null)
                .ConfigureAppConfiguration((hostingContext, config) =>
                {
                    config.AddJsonFile("appsettings.json");
                })
                .Build();

            await _host.StartAsync();
        }

        [AfterTestRun]
        public static async Task AfterTestRun()
        {
            await _host.StopAsync();
        }
    }
}
